//
//  PoverPresentationController.swift
//  SinaProject
//
//  Created by guochong on 16/4/21.
//  Copyright © 2016年 吴学宇. All rights reserved.
//

import UIKit

class PoverPresentationController: UIPresentationController {
    
    var prsentFrame = CGRectZero
    
    
//   override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
//    
//      super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
//    }

    override func containerViewWillLayoutSubviews() {
        
        if prsentFrame == CGRectZero {
            
            presentedView()?.frame = CGRect(x: 100, y: 56, width: 200, height: 200)
        }else{
            
            presentedView()?.frame = prsentFrame;
        }
      
        containerView?.insertSubview(poverView, atIndex: 0);
        
    }
    
  
     private lazy var  poverView : UIView = {
        
        let poverView = UIView();
        poverView.alpha = 0.5;
        poverView.backgroundColor = UIColor.whiteColor();
        
        poverView.frame = UIScreen.mainScreen().bounds;
        
        // 2.添加监听
      let tap =   UITapGestureRecognizer(target: self, action: #selector(PoverPresentationController.tap(_:)));
    
        poverView.addGestureRecognizer(tap);
        
        return poverView;
        
        
        
        
    }();
    
    func tap(tap : UITapGestureRecognizer) -> Void {
        
        self.presentedViewController.dismissViewControllerAnimated(true, completion: nil);
        
        
    }
    
    
}
